<template>
    <div>
      <el-form :model="queryParams" ref="queryForm" :inline="true" style="margin-left: 10px; margin-top: 20px">
        <el-form-item label="请输入年度" prop="duringyear">
          <el-input
            v-model="queryParams.duringyear"
            placeholder="请输入年度查询"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['county:credit:export']"
          >导出</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
        <el-table-column width="120" label="年度" align="center" prop="duringYear" fixed="left" />
        <el-table-column label="借款人信息(学生)" align="center" >
          <el-table-column width="120" label="QQ" align="center" prop="qq" />
          <el-table-column width="180" label="学生身份证" align="center" prop="cardIdentity" />
          <el-table-column width="120" label="户口性质" align="center" prop="residence" />
          <el-table-column width="120" label="毕业中学" align="center" prop="medium" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="户籍" align="center" prop="household" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="申贷原因" align="center" prop="applyReason" :show-overflow-tooltip="true" />
          <el-table-column width="180" label="学生身份证有效起始日期" align="center" prop="studentEffectiveCardIdentity">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.studentEffectiveCardIdentity) }}</span>
            </template>
          </el-table-column>
          <el-table-column width="180" label="学生身份证有效结束日期" align="center" prop="studentInvalidCardIdentity" >
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.studentInvalidCardIdentity) }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column width="120" label="共同借款人" align="center" :show-overflow-tooltip="true" >
          <el-table-column width="120" label="共同借款人姓名" align="center" prop="guarantor" :show-overflow-tooltip="true" />
          <el-table-column width="180" label="共同借款人联系电话" align="center" prop="guaPhone" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="关系" align="center" prop="relation" :show-overflow-tooltip="true" />
          <el-table-column width="180" label="共同借款人身份证号" align="center" prop="guaCardIdentity" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="健康状态" align="center" prop="heath" :show-overflow-tooltip="true" />
        </el-table-column>
        <el-table-column width="240" label="资助中心" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row.supportCenterProvince }} {{ scope.row.supportCenterCity }} {{ scope.row.supportCenterArea }}</span>
          </template>
        </el-table-column>
        <el-table-column width="240" label="入学前户籍所在地" align="center" >
          <template slot-scope="scope">
            <span>{{ scope.row.householdOfProvince }} {{ scope.row.householdOfCity }} {{ scope.row.householdOfArea }} {{ scope.row.householdOfCounty }} {{ scope.row.householdOfDetail }}</span>
          </template>
        </el-table-column>
        <el-table-column label="家庭住址" align="center" :show-overflow-tooltip="true" >
          <el-table-column width="240" label="家庭住址所在地" align="center" >
            <template slot-scope="scope">
              <span>{{ scope.row.homeOfProvince }} {{ scope.row.homeOfCity }} {{ scope.row.homeOfArea }} {{ scope.row.homeOfCounty }} {{ scope.row.homeOfDetail }}</span>
            </template>
          </el-table-column>
          <el-table-column width="140" label="是否与户籍地址一致" align="center" prop="isTheSameAsHousehold" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              <span>{{ scope.row.isTheSameAsHousehold === 'true' ? '是' : '否'  }}</span>
            </template>
          </el-table-column>
          <el-table-column width="140" label="家庭住址邮政编码" align="center" prop="homeOfPostcode" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="家庭电话" align="center" prop="homeOfPhone" :show-overflow-tooltip="true" />
        </el-table-column>
        <el-table-column label="就学信息" align="center" :show-overflow-tooltip="true" >
          <el-table-column label="高校名称" align="center" prop="collegeOfName" :show-overflow-tooltip="true" />
          <el-table-column width="160" label="院系名称" align="center" prop="collegeOfInstitute" :show-overflow-tooltip="true" />
          <el-table-column label="专业名称" align="center" prop="collegeOfMajor" :show-overflow-tooltip="true" />
          <el-table-column label="入学时间" align="center" prop="collegeWithStart" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.collegeWithStart) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="学历" align="center" prop="collegeOfEducation" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="学生学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
          <el-table-column label="专业类别" align="center" prop="typeOfMajor" :show-overflow-tooltip="true" />
          <el-table-column label="学制" align="center" prop="collegeOfEducationalSystem" :show-overflow-tooltip="true" />
          <el-table-column label="毕业时间" align="center" prop="collegeWithEnd" width="120" />
        </el-table-column>
        <el-table-column width="120" label="资格审查确认" align="center" :show-overflow-tooltip="true" >
          <el-table-column width="120" label="资格审查单位" align="center" prop="countyUnit" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="是否盖章" align="center" prop="isSeal" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="盖章日期" align="center" prop="sealDate" :show-overflow-tooltip="true" />
          <el-table-column width="120" label="学生签字日期" align="center" prop="signatureDate"/>
        </el-table-column>
        <el-table-column label="就业信息" align="center" :show-overflow-tooltip="true" >
          <el-table-column label="工作单位" align="center" prop="workFeature" :show-overflow-tooltip="true" />
          <el-table-column label="单位性质" align="center" prop="phoneOfUnit" :show-overflow-tooltip="true" />
          <el-table-column label="单位电话" align="center" prop="postCodeOfUnit" :show-overflow-tooltip="true" />
          <el-table-column width="140" label="单位邮政编码" align="center" prop="addressOfUnit" :show-overflow-tooltip="true" />
          <el-table-column label="单位地址" align="center" prop="addressOfUnit" :show-overflow-tooltip="true" />
        </el-table-column>
        <el-table-column label="变更" align="center" prop="changeForReason" :show-overflow-tooltip="true" />
        <el-table-column width="120" label="返校校验码" fixed="right" align="center" prop="rebackCode" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <el-tag type="info" effect="dark">{{ scope.row.rebackCode ? scope.row.rebackCode : '未录入' }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column width="160" label="返校回执单" fixed="right" align="center" prop="uploadReceiptWord" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <el-button :disabled="!scope.row.uploadReceiptWord" @click="showPdfDetail(scope.row)" :type="scope.row.uploadReceiptWord ? 'success' : 'info'" size="small" effect="dark">{{ scope.row.uploadReceiptWord ? '点击放大预览' : '未上传' }}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <el-dialog
        :visible.sync="dialogVisible"
        width="60%"
        style="height: 540px"
        >
        <iframe style="width: 766px; height: 510px; margin-left: -20px; margin-top: -60px" :src="currentPdfPath"></iframe >
      </el-dialog>

    </div>
</template>

<script>
  import { listData, getData, delData, addData, updateData, exportData } from "@/api/county/credit";
  import { listUser, getUser } from "@/api/system/user";
  import { regionData,CodeToText } from 'element-china-area-data'

  export default {
    components: {
    },
    data() {
      return {
        currentPdfPath: null,
        dialogVisible: false,
        electronicImagePath: '',
        now_creditId: '',
        current_creditId: '',
        pdfPath: '',
        options: regionData,
        selectedOptions: [],
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 学生贷款表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 状态数据学生贷款
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          creditName: undefined,
          userName: undefined,
          status: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
      };
    },
    created() {
      const userId = this.$route.params && this.$route.params.userId;
      this.getUser(userId);
      this.getUserList();
    },
    methods: {
      handleChangeSupportCenter (value) {
        let data = CodeToText[value[0]]+", "+ CodeToText[value[1]]+", "+ CodeToText[value[2]];
        this.form.supportCenterProvince = CodeToText[value[0]]
        this.form.supportCenterCity = CodeToText[value[1]]
        this.form.supportCenterArea = CodeToText[value[2]]
        console.log(data)
      },
      handleChangeHousehold (value) {
        let data = CodeToText[value[0]]+", "+ CodeToText[value[1]]+", "+ CodeToText[value[2]];
        this.form.householdOfProvince = CodeToText[value[0]]
        this.form.householdOfCity = CodeToText[value[1]]
        this.form.householdOfArea = CodeToText[value[2]]
        console.log(data)
      },
      handleChangeHome (value) {
        let data = CodeToText[value[0]]+", "+ CodeToText[value[1]]+", "+ CodeToText[value[2]];
        this.form.homeOfProvince = CodeToText[value[0]]
        this.form.homeOfCity = CodeToText[value[1]]
        this.form.homeOfArea = CodeToText[value[2]]
        console.log(data)
      },
      /** 查询学生贷款类型详细 */
      getUser(userId) {
        getUser(userId).then(response => {
          this.queryParams.userName = response.data.userName;
          this.getList();
        });
      },
      /** 查询学生贷款类型列表 */
      getUserList() {
        listUser().then(response => {
        });
      },
      /** 查询学生贷款数据列表 */
      getList() {
        this.loading = true;
        listData(this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          creditId: undefined,
          duringYear: undefined,
          qq: undefined,
          birth: undefined,
          cardIdentity: undefined,
          residence: undefined,
          medium: undefined, household: undefined,
          email: undefined, address: undefined, postcode: undefined,
          guarantor: undefined, guaPhone: undefined, relation: undefined,
          guaCardIdentity: undefined, heath: undefined,
          applyReason: undefined, signatureDate: undefined, countryUnit: undefined,
          isSeal: undefined, sealDate: undefined, studentEffectiveCardIdentity: undefined,
          studentInvalidCardIdentity: undefined, supportCenterProvince: undefined,
          supportCenterCity: undefined, supportCenterArea: undefined,
          householdOfProvince: undefined, householdOfCity: undefined,
          householdOfArea: undefined, householdOfCounty: undefined,
          householdOfDetail: undefined, homeOfProvince: undefined,
          homeOfCity: undefined, homeOfArea: undefined, homeOfCounty: undefined,
          homeOfDetail: undefined, isTheSameAsHousehold: undefined,
          homeOfPostcode: undefined, homeOfPhone: undefined, concatOfName: undefined,
          concatWorkUnit: undefined, concatOfPhone: undefined, concatOfCardIdentity: undefined,
          collegeOfName: undefined, collegeOfInstitute: undefined,
          collegeOfMajor: undefined, collegeOfEducation: undefined,
          collegeWithStart: undefined, studentNo: undefined, typeOfMajor: undefined,
          collegeOfEducationalSystem: undefined,
          collegeWithEnd: undefined, workUnit: undefined, workFeature: undefined,
          phoneOfUnit: undefined, postcodeOfUnit: undefined, addressOfUnit: undefined,
          changeForReason: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加学生贷款数据";
        this.form.userName = this.queryParams.userName;
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.creditId)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.current_creditId = row.creditId
        this.now_creditId = row.creditId
        this.electronicImagePath = 'data:image/png;base64,' + row.electronicImage
        this.pdfPath = row.pdfWithSignaturePath
        console.log(this.pdfPath)
        const creditId = row.creditId || this.ids
        getData(creditId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改学生贷款数据";
        });
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.creditId != undefined) {
              updateData(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addData(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const creditIds = row.creditId || this.ids;
        this.$confirm('是否确认删除学生贷款编码为"' + creditIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delData(creditIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportData(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleDownload(file) {
        console.log(file);
      },
      handleSuccess(response, file, fileList) {
        this.$notify({
          title: '身份证照上传成功',
          type: 'success',
          duration: 2500
        })
      },
      // 监听上传失败
      handleError(e, file, fileList) {
        const msg = JSON.parse(e.message)
        this.$notify({
          title: msg.message,
          type: 'error',
          duration: 2500
        })
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      showPdfDetail(row) {
        this.dialogVisible = true
        this.currentPdfPath = 'http://localhost:8080' + row.uploadReceiptWord
      }
    },
  };
</script>

<style scoped>

</style>
